Karten erstellen mit R

Jan-Philipp Kolb

23 November 2017

Gliederung

library(knitr)
setwd("D:/Daten/GitHub/GeoData/presentations/ps_user_stuttgart")
purl("ps_user_stuttgart_part3.Rmd")

Motivation - Deutschlands größte Klimasünder

Hello World

library(maps)
map()

Das Paket maps - detailierter

Grenzen sind recht grob:

map("world", "Germany")

Das Paket maps - Mehr Information

data(world.cities)
map("france")
map.cities(world.cities,col="blue")

Das Paket maptools

library(maptools)
data(wrld_simpl)
plot(wrld_simpl,col="royalblue")

Das Paket sp

library(sp)
spplot(wrld_simpl,"POP2005")

Das Paket raster

library(raster)
LUX1 <- getData('GADM', country='LUX', level=1)
plot(LUX1)

Daten für das Luxemburg Beispiel

kable(head(LUX1@data[,1:6]))
OBJECTID ID_0 ISO NAME_0 ID_1 NAME_1
1 131 LUX Luxembourg 1 Diekirch
2 131 LUX Luxembourg 2 Grevenmacher
3 131 LUX Luxembourg 3 Luxembourg

Kreise in Deutschland

library(maptools)
krs <- readShapePoly("vg250_ebenen/vg250_krs.shp")
plot(krs)

Ortsnetzbereiche

Quelle: Bundesnetzagentur

VORWAHL NAME KENNUNG
0 04651 Sylt NA
1 04668 Klanxbüll NA
2 04664 Neukirchen b Niebüll NA
3 04663 Süderlügum NA
4 04666 Ladelund NA
5 04631 Glücksburg Ostsee NA
onb <- readShapePoly("onb_grenzen.shp")
kable(head(onb@data))

Vorwahlbereiche in der Region Stuttgart

vw_stg <- c("0711", "07121", "07122")
vw_reg_stg <- onb[onb@data$VORWAHL %in% vw_stg, ]
plot(vw_reg_stg)

onbD

onbD

Einen größeren Vorwahlbereich ausschneiden

vwb <- as.character(onb@data$ONB_NUMMER)
vwb1 <- substr(vwb, 1,2)
vwb7 <- onb[vwb1=="07",]
plot(vwb7)

Das Paket rgdal

library(rgdal)
## OGR data source with driver: ESRI Shapefile 
## Source: "post_pl.shp", layer: "post_pl"
## with 8270 features
## It has 3 fields
setwd("D:/GESIS/Workshops/GeoDaten/data/")
PLZ <- readOGR ("post_pl.shp","post_pl")
library(rgdal)
PLZ <- readOGR ("post_pl.shp","post_pl")

PLZ-Bereiche in Stuttgart

SG <- PLZ[PLZ@data$PLZORT99=="Stuttgart",]
plot(SG,col="chocolate1")

PLZ-Bereiche in Berlin

BE <- PLZ[PLZ@data$PLZORT99%in%c("Berlin-West","Berlin (östl. Stadtbezirke)"),]
plot(BE,col="chocolate2")

Exkurs - Open Street Map

<www.openstreetmap.org/export>

OpenStreetMap - Map Features

Daten verbinden - Bäckereien in Berlin

OSM als Datenquelle

(load("data/info_bar_Berlin.RData"))
## [1] "info"
addr.postcode addr.street name lat lon
79675952 13405 Scharnweberstraße Albert’s 52.56382 13.32885
86005430 NA NA Newton Bar 52.51293 13.39123
111644760 NA NA No Limit Shishabar 52.56556 13.32093
149607257 NA NA en passant 52.54420 13.41298
248651127 10115 Bergstraße Z-Bar 52.52953 13.39564
267780050 10405 Christburger Straße Immertreu 52.53637 13.42509

Matching

tab_plz <- table(info_be$addr.postcode)
ind <- match(BE@data$PLZ99_N,names(tab_plz))
ind
##   [1]  1  2  3  4  5  6  7  8 NA  9 NA NA NA NA NA 10 11 12 NA 13 14 15 16
##  [24] 17 18 19 20 21 22 23 24 25 NA 26 27 28 29 NA NA NA NA 30 NA 31 32 33
##  [47] 34 35 NA NA 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 NA 52 53
##  [70] NA 54 55 NA NA NA 56 57 58 59 60 NA NA NA NA NA 61 NA NA NA 62 NA NA
##  [93] NA NA NA NA NA NA NA 63 NA NA 64 NA 65 NA NA NA 66 NA NA NA NA 67 NA
## [116] NA 68 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
## [139] NA 69 70 NA 71 72 73 74 75 NA 76 NA NA NA NA NA NA NA NA NA NA NA NA
## [162] 77 NA 78 79 NA NA NA NA 80 NA NA NA NA 81 NA 82 83 84 NA NA NA NA NA
## [185] NA NA NA 85 NA NA

Daten anspielen

BE@data$num_plz <- tab_plz[ind]

Das Paket tmap

library(tmap)
BE@data$num_plz[is.na(BE@data$num_plz)] <- 0
qtm(BE,fill = "num_plz")

Mehr Informationen einbinden

load("data/osmsa_PLZ_14.RData")
PLZ99 PLZ99_N PLZORT99 nname EWZ_gem area_d EWZ_gemplz place_id osm_type osm_id lat lon display_name class type importance state city county plz2ort bakery bar biergarten butcher cafe chemist clothes college store food general cream kiosk mall pub restaurant supermarket population_density BLA gadmbla gadmkreis stop yes gadmgem gadmgemtyp gadmgem2 gadmgemtyp2 ort2plz ODdat zenEinw crossing bus_stop street_lamp traffic_signals land_cover.index land_cover.value land_cover.description elevation.value temp_Jan temp_Feb temp_Mar temp_Apr temp_May temp_Jun temp_Jul temp_Aug temp_Sep temp_Oct temp_Nov temp_Dez
0 01067 1067 Dresden Dresden, Stadt 512354 0.0008602 20494.16 144969068 relation 191645 51.0493286 13.7381437 Dresden, Sachsen, Deutschland place city 0.8162766 Sachsen Dresden Dresden 25 17 10 0 4 28 2 45 0 0 21 0 1 3 0 8 100 6 567 14 Sachsen Dresden 101 0 Dresden Einheitsgemeinde Dresden Stadt 1 0 4.0 121 48 162 87 22 Artificial surfaces and associated areas urban, water, vegetation, mountains, etc. 112 -0.7 0.4 3.9 8.4 13.3 16.9 18.5 18.0 14.3 9.8 4.4 1.0
1 01069 1069 Dresden Dresden, Stadt 512354 0.0006819 20494.16 144969068 relation 191645 51.0493286 13.7381437 Dresden, Sachsen, Deutschland place city 0.8162766 Sachsen Dresden Dresden 25 20 6 0 9 24 5 41 0 0 28 0 0 3 0 2 22 9 498 14 Sachsen Dresden 83 0 Dresden Einheitsgemeinde Dresden Stadt 1 0 5.0 113 40 105 96 22 Artificial surfaces and associated areas urban, water, vegetation, mountains, etc. 115 -0.8 0.3 3.8 8.4 13.3 16.7 18.4 17.9 14.4 9.9 4.4 1.0
2 01097 1097 Dresden Dresden, Stadt 512354 0.0004382 20494.16 144969068 relation 191645 51.0493286 13.7381437 Dresden, Sachsen, Deutschland place city 0.8162766 Sachsen Dresden Dresden 25 22 9 0 4 22 3 28 0 0 23 0 0 3 0 15 49 14 567 14 Sachsen Dresden 40 0 Dresden Einheitsgemeinde Dresden Stadt 1 0 5.5 98 20 33 55 22 Artificial surfaces and associated areas urban, water, vegetation, mountains, etc. 115 -0.7 0.3 3.8 8.4 13.3 16.7 18.4 18.0 14.4 9.9 4.5 1.0
3 01099 1099 Dresden Dresden, Stadt 512354 0.0067740 20494.16 144969068 relation 191645 51.0493286 13.7381437 Dresden, Sachsen, Deutschland place city 0.8162766 Sachsen Dresden Dresden 25 18 35 5 2 35 1 33 0 1 30 0 2 0 0 25 59 6 567 14 Sachsen Dresden 88 0 Dresden Einheitsgemeinde Dresden Stadt 1 0 0.0 38 41 24 37 4 Tree Cover, needle-leaved, evergreen urban, water, vegetation, mountains, etc. 250 -1.2 -0.3 3.1 7.6 12.5 16.0 17.6 17.4 13.7 9.3 3.8 0.4
4 01109 1109 Dresden Dresden, Stadt 512354 0.0034973 20494.16 144969068 relation 191645 51.0493286 13.7381437 Dresden, Sachsen, Deutschland place city 0.8162766 Sachsen Dresden Dresden 25 14 0 0 3 4 1 5 0 0 7 0 0 0 0 0 17 4 567 14 Sachsen Dresden 242 0 Dresden Einheitsgemeinde Dresden Stadt 1 0 1.5 47 119 230 58 22 Artificial surfaces and associated areas urban, water, vegetation, mountains, etc. 216 -1.0 -0.1 3.2 7.8 12.7 16.1 17.7 17.6 13.9 9.3 3.9 0.6
5 01127 1127 Dresden Dresden, Stadt 512354 0.0003626 20494.16 144969068 relation 191645 51.0493286 13.7381437 Dresden, Sachsen, Deutschland place city 0.8162766 Sachsen Dresden Dresden 25 6 1 0 3 4 0 6 0 0 6 0 0 0 0 5 13 3 567 14 Sachsen Dresden 44 0 Dresden Einheitsgemeinde Dresden Stadt 1 0 4.5 204 22 36 12 22 Artificial surfaces and associated areas urban, water, vegetation, mountains, etc. 112 -0.7 0.4 3.9 8.4 13.4 16.9 18.4 18.0 14.4 9.8 4.4 1.1

OSM-Daten - Bäckereien in Stuttgart

qtm(PLZ_SG,fill="bakery")

In welchem PLZ Bereich sind die meisten Bäckereien

kable(PLZ_SG@data[which.max(PLZ_SG$bakery),c("PLZ99","lat","lon","bakery")])
PLZ99 lat lon bakery
4964 70173 48.7784485 9.1800132 30

Das Paket ggmap

library(ggmap)
lon_plz <- PLZ_SG@data[which.max(PLZ_SG$bakery),"lon"]
lat_plz <- PLZ_SG@data[which.max(PLZ_SG$bakery),"lat"]
mp_plz <- as.numeric(c(lon_plz,lat_plz))
qmap(location = mp_plz,zoom=15)

Das R-Paket RDSTK

library("RDSTK")

Die Daten für Stuttgart

PLZ_SG <- PLZ[PLZ@data$PLZORT99=="Stuttgart",]
Type_landcover Freq
Artificial surfaces and associated areas 26
Cultivated and managed areas 8
Tree Cover, needle-leaved, evergreen 1

Eine Karte der Flächenbedeckung erstellen

qtm(PLZ_SG,fill="land_cover.value")

Die Höhe in Stuttgart

qtm(PLZ_SG,fill="elevation.value")

Zensus Atlas

https://ergebnisse.zensus2011.de/

Zensus Datenbank

Zensus Datenbank